package leetcode_1_200;

import node.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_144 {
    public static void main(String[] args) {
        System.out.println(preorderTraversal(new TreeNode(1, null, new TreeNode(2, new TreeNode(3), null))));
    }
    private static List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        f(ans, root);
        return ans;
    }
    private static void f(List<Integer> ans, TreeNode node){
        if (node == null)
            return;
        ans.add(node.val);
        f(ans, node.left);
        f(ans, node.right);
    }
}
